package com.ruoyi.bearing.controller;

import com.ruoyi.bearing.domain.BearingModel;
import com.ruoyi.bearing.service.IBearingModelService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 轴承型号管理
 */
@Api("轴承型号管理")
@RestController
@RequestMapping("/bearingData/bearingModel")
public class BearingModelController extends BaseController {
    @Autowired
    private IBearingModelService bearingModelService;

    /**
     * 查询轴承型号列表
     */
    @ApiOperation("查询轴承型号列表")
    @PreAuthorize("@ss.hasPermi('bearingData:bearingModel:list')")
    @GetMapping("/list")
    public TableDataInfo list(BearingModel bearingModel) {
        startPage();
        List<BearingModel> list = bearingModelService.selectBearingModelList(bearingModel);
        return getDataTable(list);
    }

    /**
     * 导出轴承型号列表
     */
    @ApiOperation("导出轴承型号列表")
    @PreAuthorize("@ss.hasPermi('bearingData:bearingModel:export')")
    @Log(title = "轴承型号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BearingModel bearingModel) {
        List<BearingModel> list = bearingModelService.selectBearingModelList(bearingModel);
        ExcelUtil<BearingModel> util = new ExcelUtil<BearingModel>(BearingModel.class);
        util.exportExcel(response, list, "轴承型号数据");
    }

    /**
     * 获取轴承型号详细信息
     */
    @ApiOperation("获取轴承型号详细信息")
    @PreAuthorize("@ss.hasPermi('bearingData:bearingModel:query')")
    @GetMapping(value = "/{bid}")
    public AjaxResult getInfo(@PathVariable("bid") String bid) {
        return success(bearingModelService.selectBearingModelByBid(bid));
    }

    /**
     * 新增轴承型号
     */
    @ApiOperation("新增轴承型号")
    @PreAuthorize("@ss.hasPermi('bearingData:bearingModel:add')")
    @Log(title = "轴承型号", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BearingModel bearingModel) {
        return toAjax(bearingModelService.insertBearingModel(bearingModel));
    }

    /**
     * 修改轴承型号
     */
    @ApiOperation("修改轴承型号")
    @PreAuthorize("@ss.hasPermi('data:bearingModel:edit')")
    @Log(title = "轴承型号", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BearingModel bearingModel) {
        return toAjax(bearingModelService.updateBearingModel(bearingModel));
    }

    /**
     * 删除轴承型号
     */
    @ApiOperation("删除轴承型号")
    @PreAuthorize("@ss.hasPermi('bearingData:bearingModel:remove')")
    @Log(title = "轴承型号", businessType = BusinessType.DELETE)
    @DeleteMapping("/{bids}")
    public AjaxResult remove(@PathVariable String[] bids) {
        return toAjax(bearingModelService.deleteBearingModelByBids(bids));
    }
}
